﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;
using System.Data.SqlClient;
using DAL;


namespace BLL
{
    public class ForBorrowBooks
    {
        public string SeeReaderName(string ReaderID)
        {
            String sql = string.Format(@"select ReaderName from Reader where ReaderID = '{0}'", ReaderID);
            string ReaderName = DBHelper.ExecuteScalar(sql).ToString();
            return ReaderName;
        }
        public int AddBorrow(int BookID,string ReaderID, string BorrowDate, string ReturnDate)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("INSERT INTO Borrow (BookID, ReaderID, BorrowDate, ReturnDate) VALUES ({0}, '{1}', '{2}', '{3}');",BookID,ReaderID,BorrowDate,ReturnDate);
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
        public int UpdateBookState(int StateID,int BookID)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"update Books set StateID = {0} where BookID = {1}", StateID, BookID);
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
        public int UpdateReader(string ReaderID)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"update Reader set BorrowBook = BorrowBook - 1,ReturnBook = ReturnBook + 1 where ReaderID = '{0}';", ReaderID);
            int i = DBHelper.ExecuteNonQuery(sb.ToString());
            return i;
        }
        public SqlDataReader SeeReaderNameByReaderID(string ReaderID)
        {
            string sql = string.Format(@"select readerName from Reader where ReaderID = '{0}'", ReaderID);
            //执行
            SqlDataReader reader = DBHelper.ExecuteReader(sql);
            return reader;
        }
    }
}
